﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Globalization;
using System.IO;

public partial class DayToDayManagement_ProductSalesStatistics : System.Web.UI.Page
{
    private decimal TotalQuantity
    {
        get
        {
            decimal totalQuantity = 0.00M;
            if (ViewState["TotalQuantity"] != null)
            {
                totalQuantity = Convert.ToDecimal(ViewState["TotalQuantity"]);
            }
            return totalQuantity;
        }
        set
        {
            ViewState["TotalQuantity"] = value;
        }
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    private decimal TotalSamt
    {
        get
        {
            decimal totalSamt = 0.00M;
            if (ViewState["TotalSamt"] != null)
            {
                totalSamt = Convert.ToDecimal(ViewState["TotalSamt"]);
            }
            return totalSamt;
        }
        set
        {
            ViewState["TotalSamt"] = value;
        }
    }
    private decimal TotalAamt
    {
        get
        {
            decimal totalAamt = 0.00M;
            if (ViewState["TotalAamt"] != null)
            {
                totalAamt = Convert.ToDecimal(ViewState["TotalAamt"]);
            }
            return totalAamt;
        }
        set
        {
            ViewState["TotalAamt"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("900700");
    }
    private void Bind( Boolean isExport)
    {
        try
        {
            System.Web.UI.WebControls.DataList dl = null;
            DataSet myds = null;
            this.TotalQuantity = 0.00M;
            this.TotalSamt = 0.00M;
            this.TotalAamt = 0.00M;
            #region 订单、退货单都统计
            if (dropBillType.SelectedValue == "all")
            {
                #region 颜色、尺码都不统计
                if (chkColor.Checked == false && chkSize.Checked == false)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }


                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("all", "", "", "", "", "", "", "", "", sbOrderDocWhere.ToString(), sbReturnDocWhere.ToString());

                    dlistIncludeNone.DataSource = myds;
                    dl = dlistIncludeNone;//dl为空

                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();

                }
                #endregion
                #region 统计颜色 不统计尺码
                else if (chkColor.Checked == true && chkSize.Checked == false)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }


                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[ColorCode] varchar(20),[ColorName] varchar(200),";
                    string insertString = "[ColorCode],[ColorName],";
                    string selectOrderDocString = "od_colorcode,GUIGE1.GGMC AS ColorName,";
                    string orderDocLeftJoinString = " left join GUIGE1 on orderdetail.od_colorcode = GUIGE1.GGDM ";
                    string orderDocGroupByString = "od_colorcode,GUIGE1.GGMC,";
                    string selectReturnDocString = "rdd_colorcode,GUIGE1.GGMC AS ColorName,";
                    string returnDocLeftJoinString = " left join GUIGE1 on RETURNDOCDETAIL.rdd_colorcode = GUIGE1.GGDM ";
                    string returnDocGroupByString = "rdd_colorcode,GUIGE1.GGMC,";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("all", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, sbOrderDocWhere.ToString(), sbReturnDocWhere.ToString()); 
                    dlistOnlyIncludeColor.DataSource = myds; 
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();
                }
                #endregion
                #region 不统计颜色 统计尺码
                else if (chkColor.Checked == false && chkSize.Checked == true)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }


                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[SizeCode] varchar(20),[SizeName] varchar(200),";
                    string insertString = "[SizeCode],[SizeName],";
                    string selectOrderDocString = "od_sizecode,GUIGE2.GGMC AS SizeName,";
                    string orderDocLeftJoinString = " left join GUIGE2 on orderdetail.od_sizecode = GUIGE2.GGDM ";
                    string orderDocGroupByString = "od_sizecode,GUIGE2.GGMC,";
                    string selectReturnDocString = "rdd_sizecode,GUIGE2.GGMC AS SizeName,";
                    string returnDocLeftJoinString = " left join GUIGE2 on RETURNDOCDETAIL.rdd_sizecode = GUIGE2.GGDM ";
                    string returnDocGroupByString = "rdd_sizecode,GUIGE2.GGMC,";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    myds= new BLL.ORDERDETAIL().GetProductSalesStatistics("all", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, sbOrderDocWhere.ToString(), sbReturnDocWhere.ToString());
                    dlistOnlyIncludeSize.DataSource = myds;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();
                }
                #endregion
                #region 颜色、尺码都统计
                else if (chkColor.Checked == true && chkSize.Checked == true)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }


                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[ColorCode] varchar(20),[SizeCode] varchar(20),[ColorName] varchar(200),[SizeName] varchar(200),";
                    string insertString = "[ColorCode],[SizeCode],[ColorName],[SizeName],";
                    string selectOrderDocString = "od_colorcode,od_sizecode,GUIGE1.GGMC AS ColorName,GUIGE2.GGMC AS SizeName,";
                    string orderDocLeftJoinString = " left join GUIGE1 on orderdetail.od_colorcode = GUIGE1.GGDM left join GUIGE2 on orderdetail.od_sizecode = GUIGE2.GGDM ";
                    string orderDocGroupByString = "od_colorcode,od_sizecode,GUIGE1.GGMC,GUIGE2.GGMC,";
                    string selectReturnDocString = "rdd_colorcode,rdd_sizecode,GUIGE1.GGMC AS ColorName,GUIGE2.GGMC AS SizeName,";
                    string returnDocLeftJoinString = " left join GUIGE1 on RETURNDOCDETAIL.rdd_colorcode = GUIGE1.GGDM left join GUIGE2 on RETURNDOCDETAIL.rdd_sizecode = GUIGE2.GGDM ";
                    string returnDocGroupByString = "rdd_colorcode,rdd_sizecode,GUIGE1.GGMC,GUIGE2.GGMC,";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("all", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, sbOrderDocWhere.ToString(), sbReturnDocWhere.ToString());
                    dlistIncludeAll.DataSource = myds;
                    dlistIncludeAll.DataBind();
                }
                #endregion
            }
            #endregion
            #region 统计订单 退货单不统计
            else if (dropBillType.SelectedValue == "order")
            {
                #region 颜色、尺码都不统计
                if (chkColor.Checked == false && chkSize.Checked == false)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    myds= new BLL.ORDERDETAIL().GetProductSalesStatistics("order", "", "", "", "", "", "", "", "", sbOrderDocWhere.ToString(), "");
                    dlistIncludeNone.DataSource = myds;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();

                }
                #endregion
                #region 统计颜色 不统计尺码
                else if (chkColor.Checked == true && chkSize.Checked == false)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[ColorCode] varchar(20),[ColorName] varchar(200),";
                    string insertString = "[ColorCode],[ColorName],";
                    string selectOrderDocString = "od_colorcode,GUIGE1.GGMC AS ColorName,";
                    string orderDocLeftJoinString = " left join GUIGE1 on orderdetail.od_colorcode = GUIGE1.GGDM ";
                    string orderDocGroupByString = "od_colorcode,GUIGE1.GGMC,";
                    string selectReturnDocString = "";
                    string returnDocLeftJoinString = "";
                    string returnDocGroupByString = "";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("order", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, sbOrderDocWhere.ToString(), "");
                    dlistOnlyIncludeColor.DataSource = myds;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();
                }
                #endregion
                #region 不统计颜色 统计尺码
                else if (chkColor.Checked == false && chkSize.Checked == true)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[SizeCode] varchar(20),[SizeName] varchar(200),";
                    string insertString = "[SizeCode],[SizeName],";
                    string selectOrderDocString = "od_sizecode,GUIGE2.GGMC AS SizeName,";
                    string orderDocLeftJoinString = " left join GUIGE2 on orderdetail.od_sizecode = GUIGE2.GGDM ";
                    string orderDocGroupByString = "od_sizecode,GUIGE2.GGMC,";
                    string selectReturnDocString = "";
                    string returnDocLeftJoinString = "";
                    string returnDocGroupByString = "";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("order", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, sbOrderDocWhere.ToString(), "");
                    dlistOnlyIncludeSize.DataSource = myds;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();
                }
                #endregion
                #region 颜色、尺码都统计
                else if (chkColor.Checked == true && chkSize.Checked == true)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbOrderDocWhere = new StringBuilder();
                    sbOrderDocWhere.Append(dropDelivery.SelectedValue == "-1" ? "" : " and order_send=" + dropDelivery.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderAcheck.SelectedValue == "-1" ? "" : " and ORDER_ACHECK=" + dropOrderAcheck.SelectedValue + " ");
                    sbOrderDocWhere.Append(dropOrderClear.SelectedValue == "-1" ? "" : " and ORDER_CLEAR=" + dropOrderClear.SelectedValue + " ");
                    sbOrderDocWhere.Append(txtOrderStartDate.Text.Trim() == "" ? "" : " and order_createdate>='" + txtOrderStartDate.Text.Trim() + "' ");
                    sbOrderDocWhere.Append(txtOrderEndDate.Text.Trim() == "" ? "" : " and order_createdate<='" + txtOrderEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidOrderProduct.Value != "")
                    {
                        string[] orderProductsId = hidOrderProduct.Value.Split(',');
                        StringBuilder tempOrderProductId = new StringBuilder();
                        for (int i = 0; i < orderProductsId.Length; i++)
                        {
                            tempOrderProductId.Append("'" + orderProductsId[i] + "',");
                        }

                        sbOrderDocWhere.Append(" and od_cmdcode in(" + tempOrderProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[ColorCode] varchar(20),[SizeCode] varchar(20),[ColorName] varchar(200),[SizeName] varchar(200),";
                    string insertString = "[ColorCode],[SizeCode],[ColorName],[SizeName],";
                    string selectOrderDocString = "od_colorcode,od_sizecode,GUIGE1.GGMC AS ColorName,GUIGE2.GGMC AS SizeName,";
                    string orderDocLeftJoinString = " left join GUIGE1 on orderdetail.od_colorcode = GUIGE1.GGDM left join GUIGE2 on orderdetail.od_sizecode = GUIGE2.GGDM ";
                    string orderDocGroupByString = "od_colorcode,od_sizecode,GUIGE1.GGMC,GUIGE2.GGMC,";
                    string selectReturnDocString = "";
                    string returnDocLeftJoinString = "";
                    string returnDocGroupByString = "";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("order", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, sbOrderDocWhere.ToString(), "");

                    dlistIncludeAll.DataSource = myds;
                    dlistIncludeAll.DataBind();
                }
                #endregion
            }
            #endregion
            #region 订单不统计 统计退货单
            else if (dropBillType.SelectedValue == "return")
            {
                #region 颜色、尺码都不统计
                if (chkColor.Checked == false && chkSize.Checked == false)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("return", "", "", "", "", "", "", "", "", "", sbReturnDocWhere.ToString());
                    dlistIncludeNone.DataSource = myds;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();

                }
                #endregion
                #region 统计颜色 不统计尺码
                else if (chkColor.Checked == true && chkSize.Checked == false)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[ColorCode] varchar(20),[ColorName] varchar(200),";
                    string insertString = "[ColorCode],[ColorName],";
                    string selectOrderDocString = "";
                    string orderDocLeftJoinString = "";
                    string orderDocGroupByString = "";
                    string selectReturnDocString = "rdd_colorcode,GUIGE1.GGMC AS ColorName,";
                    string returnDocLeftJoinString = " left join GUIGE1 on RETURNDOCDETAIL.rdd_colorcode = GUIGE1.GGDM ";
                    string returnDocGroupByString = "rdd_colorcode,GUIGE1.GGMC,";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    myds = new BLL.ORDERDETAIL().GetProductSalesStatistics("return", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, "", sbReturnDocWhere.ToString());
                    dlistOnlyIncludeColor.DataSource = myds;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();
                }
                #endregion
                #region 不统计颜色 统计尺码
                else if (chkColor.Checked == false && chkSize.Checked == true)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[SizeCode] varchar(20),[SizeName] varchar(200),";
                    string insertString = "[SizeCode],[SizeName],";
                    string selectOrderDocString = "";
                    string orderDocLeftJoinString = "";
                    string orderDocGroupByString = "";
                    string selectReturnDocString = "rdd_sizecode,GUIGE2.GGMC AS SizeName,";
                    string returnDocLeftJoinString = " left join GUIGE2 on RETURNDOCDETAIL.rdd_sizecode = GUIGE2.GGDM ";
                    string returnDocGroupByString = "rdd_sizecode,GUIGE2.GGMC,";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    myds= new BLL.ORDERDETAIL().GetProductSalesStatistics("return", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, "", sbReturnDocWhere.ToString());
                    dlistOnlyIncludeSize.DataSource = myds;
                    dlistOnlyIncludeSize.DataBind();
                    dlistIncludeAll.DataSource = null;
                    dlistIncludeAll.DataBind();
                }
                #endregion
                #region 颜色、尺码都统计
                else if (chkColor.Checked == true && chkSize.Checked == true)
                {
                    char[] charTotTrim = new char[] { ',' };
                    StringBuilder sbReturnDocWhere = new StringBuilder();
                    sbReturnDocWhere.Append(dropIntoStock.SelectedValue == "-1" ? "" : " and RD_CHECK=" + dropIntoStock.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnAcheck.SelectedValue == "-1" ? "" : " and RD_ACHECK=" + dropReturnAcheck.SelectedValue + " ");
                    sbReturnDocWhere.Append(dropReturnClear.SelectedValue == "-1" ? "" : " and RD_CLEAR=" + dropReturnClear.SelectedValue + " ");
                    sbReturnDocWhere.Append(txtReturnStartDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE>='" + txtReturnStartDate.Text.Trim() + "' ");
                    sbReturnDocWhere.Append(txtReturnEndDate.Text.Trim() == "" ? "" : " and RD_CREATEDATE<='" + txtReturnEndDate.Text.Trim() + " 23:59:59" + "' ");
                    if (hidReturnProduct.Value != "")
                    {
                        string[] returnProductsId = hidReturnProduct.Value.Split(',');
                        StringBuilder tempReturnProductId = new StringBuilder();
                        for (int i = 0; i < returnProductsId.Length; i++)
                        {
                            tempReturnProductId.Append("'" + returnProductsId[i] + "',");
                        }

                        sbReturnDocWhere.Append(" and RDD_CMDCODE in(" + tempReturnProductId.ToString().TrimEnd(charTotTrim) + ") ");

                    }

                    string tableString = "[ColorCode] varchar(20),[SizeCode] varchar(20),[ColorName] varchar(200),[SizeName] varchar(200),";
                    string insertString = "[ColorCode],[SizeCode],[ColorName],[SizeName],";
                    string selectOrderDocString = "";
                    string orderDocLeftJoinString = "";
                    string orderDocGroupByString = "";
                    string selectReturnDocString = "rdd_colorcode,rdd_sizecode,GUIGE1.GGMC AS ColorName,GUIGE2.GGMC AS SizeName,";
                    string returnDocLeftJoinString = " left join GUIGE1 on RETURNDOCDETAIL.rdd_colorcode = GUIGE1.GGDM left join GUIGE2 on RETURNDOCDETAIL.rdd_sizecode = GUIGE2.GGDM ";
                    string returnDocGroupByString = "rdd_colorcode,rdd_sizecode,GUIGE1.GGMC,GUIGE2.GGMC,";


                    dlistIncludeNone.DataSource = null;
                    dlistIncludeNone.DataBind();
                    dlistOnlyIncludeColor.DataSource = null;
                    dlistOnlyIncludeColor.DataBind();
                    dlistOnlyIncludeSize.DataSource = null;
                    dlistOnlyIncludeSize.DataBind();
                    myds= new BLL.ORDERDETAIL().GetProductSalesStatistics("return", tableString, insertString, selectOrderDocString, orderDocLeftJoinString, orderDocGroupByString, selectReturnDocString, returnDocLeftJoinString, returnDocGroupByString, "", sbReturnDocWhere.ToString());
                    dlistIncludeAll.DataSource = myds;
                    dlistIncludeAll.DataBind();
                }
                #endregion
            }
            #endregion

           //DataListToExcel(dl);
          // ExportExcel(dl, "2323");
           if ( isExport ) DataTable2Excel(myds.Tables[0]);
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            Share.Alert(this.Page, "日期输入错误，请输入有效的日期！");
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }

    }
   
    /// <summary>
    /// dataList导出Excel
    /// </summary>
    /// <param name="dataList"></param>
    public void DataListToExcel(DataList dataList)
    {
        HttpContext.Current.Response.Clear();//清除缓冲区流中的所有的内容输出 
        HttpContext.Current.Response.Buffer = true;//获取一个值，该值指示是否缓冲输出，并在完成处理整个响应之后将其发送 
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");//.xls  将http头添加到输出流  DateTime.Now.DayOfYear.ToString() 
        HttpContext.Current.Response.ContentEncoding = Encoding.UTF7;//设置输出流的http字符集 
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";//设置输出流的http MiMe类型 
        CultureInfo formatProvider = new CultureInfo("ZH-CN", true);//提供有关特定区域性的信息及如何设置日期和排序字符串的格式 
        StringWriter stringwriter = new StringWriter(formatProvider);//实现一个用于将字符串写入System.IO.TextWriter,该信息存储在基础System.Text.StringBulider中 
        HtmlTextWriter htmlwriter = new HtmlTextWriter(stringwriter);//将标记字符和文本写入到Asp.net服务器控件输出流，此类提供Asp.net服务器控件在向客户端呈现标记时所使用的格式设置功能 

        dataList.RenderControl(htmlwriter);//将服务器控件的内容输出到所提供的System.Web.UI.HtmlTextWriter对象中，如果已启用跟踪功能，则存储有关控件的跟踪信息 


        HttpContext.Current.Response.Write(stringwriter.ToString());//将一个字符数组写入http相应数据流 
        HttpContext.Current.Response.End();//将当前的所有缓冲的输出发送到客户端，停止该页的执行，并引发//System.Web.httpApplication.EndRequest事件 
    } 

    /// <summary>
    /// DataTable导出Excel
    /// </summary>
    /// <param name="dtData"></param>
    public static void DataTable2Excel(System.Data.DataTable dtData)
    {
        System.Web.UI.WebControls.DataGrid dgExport = null;
        System.Web.HttpContext curContext = System.Web.HttpContext.Current;
        System.IO.StringWriter strWriter = null;
        System.Web.UI.HtmlTextWriter htmlWriter = null;

        if (dtData != null)
        {
            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
            curContext.Response.Charset = "";

            strWriter = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

            dgExport = new System.Web.UI.WebControls.DataGrid();

            dtData.Columns.Add("发货/入库");
            dtData.Columns.Add("财务审核");
            dtData.Columns.Add("结算"); 


            dtData.Columns["TempID"].ColumnName = "序号";
            dtData.Columns["ID"].ColumnName = "单据编号";
            //dtData.Columns["SendOrReceive"].ColumnName = "发货/入库";
            //dtData.Columns["发货/入库"].DataType = Type.GetType("System.bool");  
            //dtData.Columns["Clear"].ColumnName = "财务审核";
            //dtData.Columns["财务审核"].DataType = Type.GetType("System.bool"); 
            //dtData.Columns["Acheck"].ColumnName = "结算";
            //dtData.Columns["结算"].DataType = Type.GetType("System.bool"); 
            
            dtData.Columns["CreateDate"].ColumnName = "单据生成时间";
            dtData.Columns["CMDCODE"].ColumnName = "商品代码";
            dtData.Columns["SPMC"].ColumnName = "商品ERP名称";
            dtData.Columns["CA_NAME"].ColumnName = "商品电子商务名称";
            dtData.Columns["Qty"].ColumnName = "数量";
            dtData.Columns["Sprice"].ColumnName = "标准单价";
            dtData.Columns["Disc"].ColumnName = "折扣";
            dtData.Columns["Aprice"].ColumnName = "实际单价";
            dtData.Columns["Samt"].ColumnName = "标准金额"; 
            dtData.Columns["Aamt"].ColumnName = "实际金额";

            for (int i = 0; i < dtData.Rows.Count; i++)
            {
                dtData.Rows[i]["发货/入库"] =  dtData.Rows[i]["SendOrReceive"].ToString()=="1" ? "已发货" : "未发货" ;
                dtData.Rows[i]["财务审核"] = dtData.Rows[i]["Clear"].ToString() == "1" ? "已审核" : "未审核";
                dtData.Rows[i]["结算"] = dtData.Rows[i]["Acheck"].ToString() == "1" ? "已结算" : "未结算";
            }
            //移除列
            dtData.Columns.Remove(dtData.Columns["Acheck"]);
            dtData.Columns.Remove(dtData.Columns["SendOrReceive"]);
            dtData.Columns.Remove(dtData.Columns["Clear"]);
            dtData.Columns.Remove(dtData.Columns["SendOrReceiveDate"]);
            dtData.Columns.Remove(dtData.Columns["Spprice"]);
            dtData.Columns.Remove(dtData.Columns["ItgBuy"]);
            dtData.Columns.Remove(dtData.Columns["ItgPrice"]);
            dtData.Columns.Remove(dtData.Columns["Gift"]);
            dtData.Columns.Remove(dtData.Columns["Itg"]);

            dtData.Columns.Remove(dtData.Columns["AddItg"]);
            dtData.Columns.Remove(dtData.Columns["Offer"]);
            dtData.Columns.Remove(dtData.Columns["ReturnItg"]);  


            dgExport.DataSource = dtData.DefaultView;
            dgExport.AllowPaging = false;
            dgExport.DataBind();

            dgExport.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
        }
    } 

    protected void btnSearch_Click(object sender, EventArgs e)
    { 
             Bind(false); 
    }
    protected void ExportExcel_Click(object sender, EventArgs e)
    { 
             Bind(true);   //导出excel
    } 
    protected void dlistIncludeNone_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            this.TotalQuantity += ((Label)e.Item.FindControl("lblQty")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblQty")).Text);
            this.TotalSamt += ((Label)e.Item.FindControl("lblSamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblSamt")).Text);
            this.TotalAamt += ((Label)e.Item.FindControl("lblAamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblAamt")).Text);
        }
        else if (e.Item.ItemType == ListItemType.Footer)
        {
            ((Label)e.Item.FindControl("lblTotalQty")).Text = string.Format("{0:0}", this.TotalQuantity);
            ((Label)e.Item.FindControl("lblTotalSamt")).Text = string.Format("{0:0.00}", this.TotalSamt);
            ((Label)e.Item.FindControl("lblTotalAamt")).Text = string.Format("{0:0.00}", this.TotalAamt);

        }
    }
    protected void dlistOnlyIncludeColor_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            this.TotalQuantity += ((Label)e.Item.FindControl("lblQty")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblQty")).Text);
            this.TotalSamt += ((Label)e.Item.FindControl("lblSamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblSamt")).Text);
            this.TotalAamt += ((Label)e.Item.FindControl("lblAamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblAamt")).Text);
        }
        else if (e.Item.ItemType == ListItemType.Footer)
        {
            ((Label)e.Item.FindControl("lblTotalQty")).Text = string.Format("{0:0}", this.TotalQuantity);
            ((Label)e.Item.FindControl("lblTotalSamt")).Text = string.Format("{0:0.00}", this.TotalSamt);
            ((Label)e.Item.FindControl("lblTotalAamt")).Text = string.Format("{0:0.00}", this.TotalAamt);

        }
    }
    protected void dlistOnlyIncludeSize_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            this.TotalQuantity += ((Label)e.Item.FindControl("lblQty")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblQty")).Text);
            this.TotalSamt += ((Label)e.Item.FindControl("lblSamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblSamt")).Text);
            this.TotalAamt += ((Label)e.Item.FindControl("lblAamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblAamt")).Text);
        }
        else if (e.Item.ItemType == ListItemType.Footer)
        {
            ((Label)e.Item.FindControl("lblTotalQty")).Text = string.Format("{0:0}", this.TotalQuantity);
            ((Label)e.Item.FindControl("lblTotalSamt")).Text = string.Format("{0:0.00}", this.TotalSamt);
            ((Label)e.Item.FindControl("lblTotalAamt")).Text = string.Format("{0:0.00}", this.TotalAamt);

        }
    }
    protected void dlistIncludeAll_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            this.TotalQuantity += ((Label)e.Item.FindControl("lblQty")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblQty")).Text);
            this.TotalSamt += ((Label)e.Item.FindControl("lblSamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblSamt")).Text);
            this.TotalAamt += ((Label)e.Item.FindControl("lblAamt")).Text == "" ? 0.00M : Convert.ToDecimal(((Label)e.Item.FindControl("lblAamt")).Text);
        }
        else if (e.Item.ItemType == ListItemType.Footer)
        {
            ((Label)e.Item.FindControl("lblTotalQty")).Text = string.Format("{0:0}", this.TotalQuantity);
            ((Label)e.Item.FindControl("lblTotalSamt")).Text = string.Format("{0:0.00}", this.TotalSamt);
            ((Label)e.Item.FindControl("lblTotalAamt")).Text = string.Format("{0:0.00}", this.TotalAamt);

        }
    }
}
